<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>仓储管理表| </title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="font/font-awesome.min.css" rel="stylesheet">
    <!-- NProgress -->
    <!--<link href="css/nprogress.css" rel="stylesheet">-->

    <!-- Custom Theme Style -->
    <link href="css/custom.min.css" rel="stylesheet">
</head>

<body class="nav-md">
<div class="container body">
    <div class="main_container">
        <div id="head">

        </div>



        <!-- /top navigation -->

        <!-- page content -->
        <div class="right_col" role="main">
            <div class="">
                <div class="page-title">
                    <div class="title_left">
                        <h3>仓储管理表</h3>
                    </div>


                </div>
                <div class="clearfix"></div>

                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="x_panel">

                            <div class="x_content">

                                <form class="form-horizontal form-label-left" novalidate>


                                    <span class="section">管理信息</span>

                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="orderNumber">订单号 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input style="height: 34px;width: 150px" id="orderNumber" readonly="readonly" class="form-control col-md-7 col-xs-12" data-validate-length-range="6" data-validate-words="2" name="name" placeholder="请填写正确的订单号" required="required" type="text">
                                        </div>
                                    </div>

                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="depotname">仓库名字 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <select style="height: 34px;width: 150px" id="depotname">
                                                <option value="0">---请选择---</option>

                                            </select>
                                            <span id="depotnameError" style="margin-left: 20px;line-height: 34px;color: red;display: none"></span>
                                        </div>
                                    </div>
                                    <div class="ln_solid"></div>
                                    <div class="form-group">
                                        <div class="col-md-6 col-md-offset-3">
                                            <button id="send" type="button" class="btn btn-success">保存</button>
                                            <button type="button" class="btn btn-primary" onclick="window.history.back(-1)">返回</button>

                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- /page content -->

        <!-- footer content -->
        <footer>
            <div class="pull-right">
                Gentelella - Bootstrap Admin Template by <a href="https://colorlib.com">Colorlib</a>
            </div>
            <div class="clearfix"></div>
        </footer>
        <!-- /footer content -->
    </div>
</div>

<!-- jQuery -->
<script src="js/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="js/bootstrap.min.js"></script>
<!-- FastClick -->
<script src="js/fastclick.js"></script>
<!-- NProgress -->
<script src="js/nprogress.js"></script>
<!-- validator -->

<!-- Custom Theme Scripts -->
<script src="js/custom.min.js"></script>

<!-- validator -->
<script>
    var $token=window.sessionStorage.getItem('token');
    var url = window.location.href;
    var termsId = url.split("=")[1];
    $("#orderNumber").val(termsId);

    $.ajax({
        type:"post",
        xhrFields:{withCredentials:true},
        url:"http://localhost:8081/OrderController/showDepot",
        dataType:"json",
        data:{"orderNumber":termsId,"token":$token},
        success:function (data) {
            $.each(data, function (i, depot) {
                $("#depotname").append("<option value='"+depot.id+"'>"+depot.depotname+"</option>");
            })

        },
        error:function(){
            alert("异常");
        }
    });

    $("#depotname").blur(function() {
       if ($(this).val()==0){
           $("#depotnameError").show();
           $("#depotnameError").html("请选择仓库");
       }else {
           $("#depotnameError").hide();
       }
    });

    //订单入库
    $("#send").click(function() {
        var $depotname  =$("#depotname").val();
        var $pattern = /^\d{4,5}$/;
        if ($depotname==0){
            $("#depotnameError").show();
            $("#depotnameError").html("请选择仓库");
            return;
        }else {
            $.ajax({
                type:"post",
                xhrFields:{withCredentials:true},
                url:"http://localhost:8081/OrderController/ruku",
                dataType:"json",
                data:{"orderNumber":termsId,"depotid":$depotname,"token":$token},
                success:function (data) {
                    if(data.message=="no"){
                        alert("无法入库");
                        return;
                    }else{
                        alert("入库成功!");
                        window.location.href='MyOrder.html';
                    }
                },
                error:function(){
                    alert("异常");
                }
            });
        }

    });

    // initialize the validator function
    // validator.message.date = 'not a real date';

    // validate a field on "blur" event, a 'select' on 'change' event & a '.reuired' classed multifield on 'keyup':
    // $('form')
    //     .on('blur', 'input[required], input.optional, select.required', validator.checkField)
    //     .on('change', 'select.required', validator.checkField)
    //     .on('keypress', 'input[required][pattern]', validator.keypress);

    $('.multi.required').on('keyup blur', 'input', function() {
        validator.checkField.apply($(this).siblings().last()[0]);
    });

    $('form').submit(function(e) {
        e.preventDefault();
        var submit = true;

        // evaluate the form using generic validaing
        if (!validator.checkAll($(this))) {
            submit = false;
        }

        if (submit)
            this.submit();

        return false;
    });
    $('#head').load("head.html");
</script>
<!-- /validator -->
</body>
</html>